package com.cgtong.android.adapter;

import android.widget.ImageView;
import android.text.TextUtils;

import com.blankj.utilcode.util.TimeUtils;
import com.cgtong.android.R;
import com.cgtong.android.bean.NewsBean;
import com.cgtong.android.http.ConstantManager;
import com.cgtong.android.widget.GlideApp;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * Created by Sky.Bing on 2017/10/18.
 */

public class CityDynamicListAdapter extends BaseQuickAdapter<NewsBean, BaseViewHolder> {

    public CityDynamicListAdapter() {
        super(R.layout.adapter_citydynamic, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, NewsBean newsBean) {
        baseViewHolder.setText(R.id.dynamic_title, newsBean.getTitle());
        baseViewHolder.setText(R.id.dynamic_origin, newsBean.getSources());
        baseViewHolder.setText(R.id.dynamic_time, TimeUtils.date2String(TimeUtils.string2Date(newsBean.getPublish_date(), ConstantManager.YYYY_MM_DD_FORMAT), ConstantManager.YYYY_MM_DD_FORMAT));
        if(TextUtils.isEmpty(newsBean.getPicture())){
            ((ImageView) baseViewHolder.getView(R.id.dynamic_image)).setImageResource(R.drawable.icon_default_image_empty);
        }else{
            GlideApp.with(mContext).load(newsBean.getPicture()).placeholder(R.drawable.icon_default_loading).error(R.drawable.icon_default_error).into((ImageView) baseViewHolder.getView(R.id.dynamic_image));
        }
    }
}